Data Visualization Lab #1
How do I start making a graph using the penguins dataset?
What geom layer would I use to make a graph of body_mass_g for all of the penguins in the dataset?
ggplot(data = penguins) +
_________(mapping = aes(x = body_mass_g))
What geom layer would I use to make a graph of body_mass_g for all of the penguins in the dataset?
ggplot(data = penguins) +
geom_histogram(mapping = aes(x = body_mass_g)) +
labs(
title = "Distribution of Penguin Body Mass",
x = "Body Mass (g)",
y = "Count"
) +
theme_minimal()
What geom layer would I use to make a graph of penguins by sex and species?
ggplot(data = penguins) +
_________(mapping = aes(x = species, fill = sex), position = "dodge")
Which function would I use to change the appearance of the x-axis?
ggplot(data = penguins) +
geom_bar(mapping = aes(x = species, fill = sex), position = "dodge") +
______x_discrete(labels = c("Adelie", "Chinstrap", "Gentoo"))
Which function would I use to change the appearance of the x-axis?
ggplot(data = penguins) +
geom_bar(mapping = aes(x = species, fill = sex), position = "dodge") +
scale_x_discrete(labels = c("Adelie", "Chinstrap", "Gentoo")) +
scale_fill_discrete(labels = c("Female", "Male", "NA")) +
labs(
title = "Distribution of Penguin Body Mass",
x = "Body Mass (g)",
y = "Count"
) +
theme_minimal()
What geom layer would I use to make a graph of bill length and bill depth?
ggplot(data = penguins) +
________(mapping = aes(x = bill_length_mm, y = bill_depth_mm))
What geom layer would I use to make a graph of bill length and bill depth?
ggplot(data = penguins) +
geom_point(mapping = aes(x = bill_length_mm, y = bill_depth_mm)) +
geom_smooth(
mapping = aes(x = bill_length_mm, y = bill_depth_mm),
method = "lm",
se = FALSE
) +
labs(
title = "Bill Length vs. Bill Depth",
x = "Bill Length (mm)",
y = "Bill Depth (mm)"
) +
theme_minimal()
What geom layer would I use to make a graph of flipper length by species?
ggplot(data = penguins) +
________(mapping = aes(x = sex, y = flipper_length_mm))
What geom layer would I use to make a graph of flipper length by sex?
ggplot(data = penguins) +
geom_boxplot(mapping = aes(x = sex, y = flipper_length_mm)) +
scale_x_discrete(labels = c("Female", "Male", "NA")) +
labs(
title = "Flipper Length by Sex",
x = "Sex",
y = "Flipper Length (mm)"
) +
theme_minimal()
What is missing from this graph?
ggplot(data = penguins) +
geom_boxplot(mapping = aes(x = sex, y = flipper_length_mm)) +
scale_x_discrete(labels = c("Female", "Male", "NA")) +
labs(
title = "Flipper Length by Sex",
x = "Sex",
y = "Flipper Length (mm)"
) +
theme_minimal()
What geom layer would I use to make a graph of flipper length by sex?
ggplot(data = penguins) +
geom_boxplot(mapping = aes(x = sex, y = flipper_length_mm)) +
scale_x_discrete(labels = c("Female", "Male", "NA")) +
labs(
title = "Flipper Length by Sex",
x = "Sex",
y = "Flipper Length (mm)",
caption = "Source: palmerpenguins package"
) +
theme_minimal()